package com.yanfan.dlt698_45.code;


import com.yanfan.common.ByteUtil;

/**
 * @author oliver foo
 * @description
 * @date 2023/3/21 16:17
 */
public class DataAccessCode {
    /**
     * 成功
     */
    public static final byte SUCCESS = 0x00;


    /**
     * 硬件失效
     */
    public static final byte HARDWARE_FAILURE = 0x01;

    /**
     * 暂时失效
     */
    public static final byte TEMPORARY_FAILURE = 0x02;

    /**
     * 拒绝读写
     */
    public static final byte ACCESS_DENIED = 0x03;

    /**
     * 对象未定义
     */
    public static final byte OBJECT_UNDEFINED = 0x04;

    /**
     * 对象接口类不符合
     */
    public static final byte OBJECT_INTERFACE_CLASS_MISMATCH = 0x05;

    /**
     * 对象不存在
     */
    public static final byte OBJECT_DOES_NOT_EXIST = 0x06;

    /**
     * 类型不匹配
     */
    public static final byte TYPE_MISMATCH = 0x07;

    /**
     * 越界
     */
    public static final byte OUT_OF_RANGE = 0x08;

    /**
     * 数据块不可用
     */
    public static final byte DATA_BLOCK_NOT_AVAILABLE = 0x09;

    /**
     * 分帧传输已取消
     */
    public static final byte FRAME_TRANSMISSION_CANCELED = 0x10;


    public static String getErrorMessage(byte code) {
        switch (code) {
            case HARDWARE_FAILURE:
                return "硬件失效";
            case TEMPORARY_FAILURE:
                return "暂时失效";
            case ACCESS_DENIED:
                return "拒绝读写";
            case OBJECT_UNDEFINED:
                return "对象未定义";
            case OBJECT_INTERFACE_CLASS_MISMATCH:
                return "对象接口类不符合";
            case OBJECT_DOES_NOT_EXIST:
                return "对象不存在";
            case TYPE_MISMATCH:
                return "类型不匹配";
            case OUT_OF_RANGE:
                return "越界";
            case DATA_BLOCK_NOT_AVAILABLE:
                return "数据块不可用";
            case FRAME_TRANSMISSION_CANCELED:
                return "分帧传输已取消";
            default:
                return "unknown error: " + ByteUtil.dumpHex(code);
        }
    }
}
